<?php
/**
 * Created by PhpStorm.
 * User: zjw
 * Date: 2018/5/23
 * Time: 下午1:59
 */

namespace common\jobs;

use common\helpers\sms\Sms;
use yii\base\BaseObject;
use yii\queue\Queue;
use yii\queue\RetryableJobInterface;

class TestJob extends BaseObject implements RetryableJobInterface
{
    public $phone;
    public $dataVariables;
    public $template;

    /**
     * @param Queue $queue which pushed and is handling the job
     */
    public function execute($queue)
    {
        try {
            echo $this->phone;
            echo date("Y-m-d H:i:s");
            file_put_contents("/test.log",$this->phone." ".date("Y-m-d H:i:s"),FILE_APPEND);
        } catch (\Exception $e) {
            throw $e;
        }
    }

    /**
     * @return int time to reserve in seconds
     */
    public function getTtr()
    {
        return 0;
    }

    /**
     * @param int $attempt number
     * @param \Exception $error from last execute of the job
     * @return bool
     */
    public function canRetry($attempt, $error)
    {
        return $attempt < 3;
    }
}
